package com.shop.front.controller;

import com.netflix.discovery.converters.Auto;
import com.shop.common.pojo.User;
import com.shop.front.service.ProductTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ghy
 * @version 1.0
 * @date 2020-11-02
 */
@Controller
@RequestMapping("/page")
@Slf4j
public class PageController {

    /**
     * 测试thymeleaf
     *
     * @return
     */
    @GetMapping("/test")
    public String test(Model model) {
        log.info("PageController index");

        //逻辑视图
        model.addAttribute("msg", "<h1>thymeleaf快速入门</h1>");

        model.addAttribute("num1",60);
        model.addAttribute("num2",58);

        List<User> list = new ArrayList<>();
        list.add(new User(1L, "13512345678", "123456", "jack"));
        list.add(new User(45L, "13512341234", "3652", "lucy"));
        list.add(new User(21L, "13512348888", "5241", "张三"));

        model.addAttribute("list", list);

        return "demo";
    }


    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 首页
     *
     * @return
     */
    @GetMapping("/index")
    public String index(Model model) {
        log.info("PageController index");

        model.addAttribute("types", productTypeService.findAll());

        return "index";
    }

}
